//
//  DLYesterdayIncomeVC.m
//  delongzhitou
//
//  Created by Mr.Wang on 2018/11/26.
//  Copyright © 2018 delongzhitou. All rights reserved.
//

#import "DLYesterdayIncomeVC.h"
#import "DLIncomeView.h"
#import "DLIncomeTC.h"
#import "DLScreeningView.h"


@interface DLYesterdayIncomeVC ()

@property (nonatomic, strong) DLIncomeView *incomeView;

@property (nonatomic, strong) DLScreeningView *screeningView;

@end

@implementation DLYesterdayIncomeVC

- (void) viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.navigationBar.translucent = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setUpNav];
    [self layoutSubControls];
    [self loadData];
}
- (void) loadData {
    
    NSString *postUrl = HTTPGetUserEverdayIncome;
    NSDictionary *postDic = @{@"pageNo" : @"1",
                              @"length" : @"10",
                              @"type" : @"1"
                              };
    [[DLNetWorkManager shareInstance] requestWithMethod:DLRequestMethodPOST path:postUrl parameters:postDic success:^(id  _Nonnull responseObject) {
        if (kRequestSuccess(responseObject)) {
            
            NSDictionary *resultDic = responseObject[@"result"];
            NSString *money = [NSString stringWithFormat:@"%@", resultDic[@"total"]];
            self.incomeView.money = money.doubleValue;
            //更新数据了 亲。
            
        } else {
            kShowRequestMsg(kSafeString(responseObject[@"message"]));
            
        }
    } failure:^(NSError * _Nonnull error) {
        NSLog(@"请求接口失败，错误是：%@", error);
    }];
}
- (void) setUpNav {
    self.titleView.title = @"昨日收益";
    
    UIButton *screeningButton = [UIButton buttonWithType:0];
    screeningButton.frame = CGRectMake(0, 0, 40, 30);
    [screeningButton setTitle:@"筛选" forState:UIControlStateNormal];
    screeningButton.titleLabel.font = kSystemFont(14);
    [screeningButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:screeningButton];
    [screeningButton addTarget:self action:@selector(screeningButtonClick:) forControlEvents:UIControlEventTouchUpInside];
}
- (void) screeningButtonClick:(UIButton *)button {
    button.selected = !button.selected;
    
    if (button.isSelected) {
        [UIView animateWithDuration:0.2 animations:^{
            self.screeningView.alpha = 1;
        }];
    } else {
        [UIView animateWithDuration:0.2 animations:^{
            self.screeningView.alpha = 0;
        }];
    }
}
- (void) layoutSubControls {
    
    self.view.backgroundColor = kDLViewNormalBgColor;
    
    DLIncomeView *incomeView = [[DLIncomeView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kAutoWidth(68))];
    [self.view addSubview:incomeView];
    self.incomeView = incomeView;
    
    self.plainTableView.frame = CGRectMake(0, incomeView.bottom, kScreenWidth, kScreenSafeAreaHeight - incomeView.height - kHeightNavigation);
    [self.view addSubview:self.plainTableView];
    [self.plainTableView registerClass:[DLIncomeTC class] forCellReuseIdentifier:@"DLIncomeTC"];
    self.plainTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    [self.plainTableView reloadData];
    
    DLScreeningView *screeningView = [[DLScreeningView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kAutoWidth(190))];
    [self.view addSubview:screeningView];
    self.screeningView = screeningView;
    screeningView.alpha = 0;
    [self.view bringSubviewToFront:screeningView];
}
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 77;
}
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 6;
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    DLIncomeTC *itc = [tableView dequeueReusableCellWithIdentifier:@"DLIncomeTC"];
    [itc configData];
    return itc;
}
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
